<template>
  <div class="business_container">
    <div class="nav">
          <ul class="nav_box">
            <!-- <li>
              <router-link to="/home/business/whole" active-class="active" tag="span">全部</router-link>
            </li> -->
            <li v-for="(item,index) in navlist" :key="index" class="navli">
              <router-link :to="{path:item.linkUrl,query:{typeid:item.type_id}}" active-class="active" tag="span"
              :class="{'active':navindex == item.index}" >{{item.type_name}}</router-link>
            </li>
          </ul>
          <!-- <el-input placeholder="请输入内容" v-model="keyWord" class="search_input">
            <i slot="prefix" class="el-input__icon el-icon-search" @click="searchArticle"></i>
          </el-input> -->
    </div>
    <div style="width:1300px;margin:0 auto;">
      <router-view></router-view>
    </div>
  </div>
</template>
<script>
import axios from 'axios'
import { getnavlist,searcharticle } from "@/api/business"
export default {
  data() {
      return {
         navlist:[
            {
              linkUrl:'/home/business/officespace'
            },
            {
              linkUrl:'/home/business/tips'
            },
            {
              linkUrl:'/home/business/LawWorks'
            },
            {
              linkUrl:'/home/business/financing'
            },
            {
              linkUrl:'/home/business/preferential'
            },
            {
              linkUrl:'/home/business/activity'
            },
            {
              linkUrl:'/home/business/taxation'
            },
        ],
        navtype:[],
        showsearch:0, 
        search_content:'',
        keyWord:'',
        navindex:0,
      }
  },
  created(){
    this.$root.goIndex=2
  },
  methods:{
    showSearchbox(index){
			this.showsearch = index;
    },

    fetchnavlist(){
      getnavlist().then((res)=>{
        if(res.data.code == 0){
          this.navtype = res.data.data;
          let arr2 = this.navtype.reverse();
          let navlist = [...this.navlist];
          navlist.forEach((item, i) => {
            let {type_id, type_name} = arr2[i];
            Object.assign(item, {type_id, type_name});
            this.navlist= navlist;
          });
        }
      })
      .catch((error)=>{
      })
    },

    searchArticle(){
      var reqParams = {
        keyWord :this.keyWord,
      }
      searcharticle(reqParams).then((res)=>{
        if(res.data.code == 0){
          let arr = res.data.data[0];
          let typeid = arr.type_id;
          let articelid = arr.article_id;
          switch (typeid) {
            case 1:
              this.$router.push({path:'/home/business/officespace/spacedetail/' + typeid + '/' + articelid});
              break;
            case 2:
              this.$router.push({path:'/home/business/tips/tipsdetail/' + typeid + '/' + articelid});
              break;
            case 3:
              this.$router.push({path:'/home/business/lawworks/lawworksdetail/' + typeid + '/' + articelid});
              break;
            case 4:
              this.$router.push({path:'/home/business/financing/financingdetail/' + typeid + '/' + articelid});
              break;
            case 5:
              this.$router.push({path:'/home/business/preferential/preferendetail/' + typeid + '/' + articelid});
              break;
            case 6:
              this.$router.push({path:'/home/business/activity/activitydetail/' + typeid + '/' + articelid});
              break; 
            case 7:
              this.$router.push({path:'/home/business/taxation/taxationdetail/' + typeid + '/' + articelid});
              break;    
          }
        }
      })
    }
  },
 
  mounted () {
    this.fetchnavlist();
  }
}
</script>
<style lang="scss" scoped>
@import "../../style/common.scss";
@import "./business.scss"; 
</style>
